'use strict';
// 创建db对象
const db = uniCloud.database();
// 获取 `tt_users` 集合的引用
const usersCollection = db.collection('tt_users');


exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	let {
		account,
		password
	} = event;
	if (account && password) {
		let users = await usersCollection.where({
			account,
			password
		}).get()

		if (users.data.length == 0) {
			return {
				msg: "账号或密码错误",
				code: 1
			}
		} else {
			let {
				account,
				imgUrl,
				createAt,
				_id,
				user
			} = users.data[0]
			return {
				code: 200,
				info: {
					account,
					imgUrl,
					createAt,
					_id,
					user
				}
			}
		}
	} else {
		//返回数据给客户端
		return {
			msg: "缺少参数"
		}
	}

};